package net.androy.hoola;

import java.io.InputStream;
import java.util.List;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.DefaultHttpClient;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

import android.util.Log;

public class FeedRetriever {
    private static SAXParser parser = null;
    private static XMLReader reader = null;
    private static XMLHandler handler = null;
    private static HttpUriRequest request = null;
    private static HttpResponse response = null;
    private static InputStream is = null;
    
    public static void getFeed(List handler, String category){
	try {
	    SAXParserFactory factory = SAXParserFactory.newInstance();
	    parser = factory.newSAXParser();
	    reader = parser.getXMLReader();
	    reader.setContentHandler(new XMLHandler(handler));
	    
	    DefaultHttpClient client = new DefaultHttpClient();
	    String url = "http://feeds.astrology.com/"+category;
	    Log.i("URL", url);
	    request = new HttpGet(url);
	    response = client.execute(request);
	    HttpEntity entity = response.getEntity();
	    is = entity.getContent();
	    reader.parse(new InputSource(is));
	    
	} catch (Exception e) {
	    e.printStackTrace();
	    Log.e("FeedRetriever", e.getMessage()+"");
	}

    }
}
